﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsCE.Forms;

namespace GoTextPalm.Gui
{
    public partial class CustomInputPanel : Component
    {
        public Panel Screen;
        private InputPanel inputPanel;

        private bool sipSupported = true;
        public Boolean SipSupported { get { return sipSupported; } }

        public CustomInputPanel()
        {
            InitializeComponent();
            AddInputPanel();
        }

        public CustomInputPanel(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
            AddInputPanel();
        }

        private void AddInputPanel()
        {
            try
            {
                inputPanel = new InputPanel();
                inputPanel.EnabledChanged += new EventHandler(inputPanel_EnabledChanged);
            }
            catch (NotSupportedException nse)
            {
                sipSupported = false;
            }
        }

        private void inputPanel_EnabledChanged(object sender, EventArgs e)
        {
            try
            {
                Screen.Size = inputPanel.VisibleDesktop.Size;
                if (!inputPanel.Enabled)
                    Screen.Height -= Constants.SIPBarHeight;
            }
            catch (ObjectDisposedException ex)
            {
                inputPanel.Dispose();
            }
        }

        public void Refresh()
        {
            inputPanel_EnabledChanged(null, null);
        }
    }
}
